import {createRouter, createWebHistory, RouteRecordRaw} from 'vue-router'
// import {useI18n} from "vue-i18n";
// const t = useI18n();

const Devil = () => import('../views/devil/Devil.vue')
const Control = () => import('../views/devil/control/Control.vue')
const Message = () => import('../views/devil/message/Message.vue')
const Queue = () => import('../views/devil/queue/Queue.vue')
const Old = () => import('../views/devil/old/Old.vue')
const Producer = () => import('../views/devil/producer/Producer.vue')
const Customer = () => import('../views/devil/customer/Customer.vue')
const Subscribe = () => import('../views/devil/subscribe/Subscribe.vue')
const Delay = () => import('../views/devil/delay/Delay.vue')

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    component: Devil,
    redirect: '/control',
    children: [
      {
        path: '/control',
        name: 'Control',
        component: Control,
        meta: {
          title: 'devilMQ-中控室'
        }
      }, {
        path: '/queue',
        name: 'Queue',
        component: Queue,
        meta: {
          title: 'devilMQ-队列'
        }
      }, {
        path: '/message',
        name: 'Message',
        component: Message,
        meta: {
          title: 'devilMQ-消息'
        }
      }, {
        path: '/old',
        name: 'Old',
        component: Old,
        meta: {
          title: 'devilMQ-消息'
        }
      }, {
        path: '/producer',
        name: 'Producer',
        component: Producer,
        meta: {
          title: 'devilMQ-消费者'
        }
      }, {
        path: '/customer',
        name: 'Customer',
        component: Customer,
        meta: {
          title: 'devilMQ-生产者'
        }
      }, {
        path: '/subscribe',
        name: 'Subscribe',
        component: Subscribe,
        meta: {
          title: 'devilMQ-订阅者'
        }
      }, {
        path: '/delay',
        name: 'Delay',
        component: Delay,
        meta: {
          title: 'devilMQ-延时队列消息'
        }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 前置路由
router.beforeEach((to, from, next) => {
  document.title = to.meta.title as string
  const token = window.localStorage.getItem('token')
  next()
  // if (to.path == '/login' || to.path == '/register') {
  //   next()
  // } else {
  //   if (token) {
  //     next()
  //   } else {
  //     // ElMessage({
  //     //   message: '请先登录',
  //     //   type: 'warning'
  //     // })
  //     setTimeout(() => {
  //       next('login')
  //     }, 1500)
  //   }
  // }
})

export default router
